package com.estun.backroundManagementService.modules.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.estun.backroundManagementService.modules.product.model.Product;
import com.estun.backroundManagementService.modules.product.model.ProductValue;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 产品参数表 Mapper 接口
 * </p>
 *
 * @author machine
 * @since 2023-02-14
 */
@Mapper
public interface ProductValueMapper extends BaseMapper<ProductValue> {


    @Select("SELECT * FROM product_value WHERE product_id = (SELECT product_id FROM product_value WHERE station_id = #{stationId} ORDER BY id DESC LIMIT 1)")
    List<ProductValue> selectLatestByStationId(@Param("stationId") String stationId);

    @Select("SELECT * FROM product WHERE id = (SELECT product_id FROM product_value WHERE station_id = #{stationId} ORDER BY id DESC LIMIT 1)")
    Product selectProductByStationId(@Param("stationId") String stationId);
}
